package com.xzs.thinking.dao.impl;

import com.alibaba.fastjson.JSONObject;
import com.xzs.thinking.dao.HelloWorldRedisDao;
import com.xzs.thinking.model.HelloWorldVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Repository;

import java.util.Map;

/**
 * @author : Iris.Xiao
 * @date : 2017/11/20 11:30
 * @description :
 */
@Repository
public class HelloWorldRedisDaoImpl implements HelloWorldRedisDao {
    @Autowired
    public RedisTemplate redisTemplate;

    @Override
    public void save(HelloWorldVO helloWorldVO) {
        Map map = JSONObject.parseObject(JSONObject.toJSONString(helloWorldVO),Map.class);
        redisTemplate.opsForHash().putAll("helloworld:"+helloWorldVO.getArticleId(),map);
    }

    @Override
    public Map<Object,Object> get(String id) {
        return redisTemplate.opsForHash().entries("helloworld:"+id);
    }
}
